#include "../src/combine_3.h"
#include <stdio.h>
#include <stdlib.h>
#include "../src/util_mpi.h"

int main(int argc, int **argv)
{
    int nump = 2; // each machine has 2 threads
    int numm, rk, i, thread_id;
    int combine_test_times = 100;

    MPI_Init(NULL, NULL);
    MPI_Comm_size(MPI_COMM_WORLD, &numm);
    MPI_Comm_rank(MPI_COMM_WORLD, &rk);
    init_mpi("combined_3.out");
    init_combined_barrier(nump, numm, rk);
    long start = clock();
#pragma omp parallel num_threads(nump) private(i)
    {
        i = 0;
        while (i++ < combine_test_times) {
            combined_barrier();
        }
    }
    long end = clock();
    double timeslast = (double)(end - start) / CLOCKS_PER_SEC / combine_test_times;

    fprintf(fp, "num_of_machines\n%d\navearge:\n%.10lf\n", NUM_MACHINES, timeslast);

    MPI_Finalize();

    struct rusage usage;
    getrusage(RUSAGE_SELF, &usage);
    output(&usage);

    return 0;
}

